#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ep emplace
#define rep(i, x, y) for(int i = (x); i <= (y); i++) 
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-', ch = getchar(); 
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x;
}

const int N = 2e5 + 10;

int g[N], f[N], s[N], n, Q;
pii t[N];

namespace seg {
	int val[N << 2];
	int ch[N << 2][2], rt, ndn, L[N << 2], R[N << 2], md[N << 2];
	void build(int &o, int l, int r) {
		o = ++ndn; L[o] = l; R[o] = r; val[o] = -1e9; if(l == r) return; md[o] = (l + r) >> 1;
		build(ch[o][0], l, md[o]); build(ch[o][1], md[o] + 1, r);
	}
	int pos, v;
	void upd(const int &o) {
		val[o] = max(val[o], v); if(L[o] == R[o]) return;
		if(pos <= md[o]) upd(ch[o][0]); else upd(ch[o][1]); val[o] = max(val[ch[o][0]], val[ch[o][1]]);
	}
	void init() { ndn = 0; build(rt, 0, n); }
	int xl, xr;
	int query(const int &o) {
		if(xl <= L[o] && R[o] <= xr) return val[o];
		int ans = -1e9;
		if(xl <= md[o]) ans = max(ans, query(ch[o][0]));
		if(xr > md[o]) ans = max(ans, query(ch[o][1]));
		return ans;
	}
	inline void upd(const int &pos, const int &v) { seg :: pos = pos; seg :: v = v; upd(rt); }
	inline int query(const int &l, const int &r) { xl = l; xr = r; return query(rt); }
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; rep(i, 1, n) s[i] = s[i - 1] + in;
	Q = in; rep(i, 1, Q) t[i].fi = in, t[i].se = in;
	sort(t + 1, t + Q + 1);
	int lst = 0; seg :: init(); //cerr << seg :: ndn << endl;
	rep(i, 1, Q) {
		while(lst < t[i].fi - 1) {
			g[lst + 1] = max(g[lst] + ((s[lst + 1] - s[lst]) == 0), g[lst + 1]);
			lst++; 
		}
		f[i] = g[lst] + s[t[i].se] - s[lst];
		f[i] = max(f[i], seg :: query(t[i].fi, t[i].se) + s[t[i].se]);
		//int t1 = seg :: query(t[i].fi, t[i].se) + s[t[i].se], t2 = 0;
		//rep(j, 1, i - 1)
		//   	if(t[i].fi <= t[j].se && t[i].se >= t[j].se) t2 = max(t2, f[j] + s[t[i].se] - s[t[j].se]);
		//cerr << t1 << " " << t2 << endl; assert(t1 == t2);
		g[t[i].se] = max(g[t[i].se], f[i]);
		seg :: upd(t[i].se, f[i] - s[t[i].se]);
		//if(i % 100 == 0) cerr << i << endl;
	}
	while(lst < n) {
		g[lst + 1] = max(g[lst] + ((s[lst + 1] - s[lst]) == 0), g[lst + 1]);
		lst++; 
	}
	printf("%d\n", n - g[n]);
	return 0;
}
